package com.yaxin.heshanghui.activity;

import android.os.Bundle;
import android.support.v4.app.ActivityCompat;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.framework.Utils.PreferencesHelper;
import com.framework.Utils.ToastUtil;
import com.framework.Utils.Utils;
import com.yaxin.heshanghui.R;
import com.yaxin.heshanghui.base.BiuooBaseActivity;
import com.yaxin.heshanghui.customview.TitleView;
import com.yaxin.heshanghui.utils.BiuooCustomProgressDialogUtils;


public class BiuooInputPhoneActivity extends BiuooBaseActivity implements ActivityCompat.OnRequestPermissionsResultCallback {

    private EditText et_input_phone;
    private TextView tv_next;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Utils.setTranslucentStatus(this, true);
        Utils.setStatusBarTintDrawable(this,R.mipmap.biuoo_bg_top);
        setContentView(R.layout.biuoo_activity_input_phone);
        initView();
    }


    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.tv_next:
                Utils.isCloseSoftInputMethod(this, et_input_phone, true);
                if (null == et_input_phone.getText() || TextUtils.isEmpty(et_input_phone.getText()) || !Utils.isMobileNO(et_input_phone.getText().toString())) {
                    ToastUtil.getInstance().showToast("请输入正确手机号码");
                    et_input_phone.requestFocus();
                } else {
                    BiuooCustomProgressDialogUtils.showProcessDialog(this, "检查手机号");
                    String[] array = getResources().getStringArray(R.array.biuoo_phone);
                    boolean contains = false;
                    for (int i = 0; i < array.length; i++) {
                        if (TextUtils.equals(et_input_phone.getText(), array[i])) {
                            contains = true;
                        }
                    }
                    PreferencesHelper.getInstance().putInfo("phone",et_input_phone.getText().toString());
                    if (contains) {
                        Utils.h.postDelayed(new Runnable() {
                            @Override
                            public void run() {
                                BiuooCustomProgressDialogUtils.dismissProcessDialog();
                                PreferencesHelper.getInstance().putInfo("Position","");
                                startActivity(BiuooGuideActivity.class);
                            }
                        }, 2000);
                    } else {
                        Utils.h.postDelayed(new Runnable() {
                            @Override
                            public void run() {
                                BiuooCustomProgressDialogUtils.dismissProcessDialog();
                                ToastUtil.getInstance().showToast("用户手机号不合法，请重新输入");
                            }
                        }, 2000);

                    }
                }
//                startActivity(MessageCenterActivity.class);
                break;
            default:
                break;
        }
    }


    private void initView() {
        TitleView titleView = (TitleView) findViewById(R.id.titleView);
        titleView.setTitle("导购");
        et_input_phone = (EditText) findViewById(R.id.et_input_phone);
    }
}
